import axios from "axios";
import { getToken } from "./utils/setToken.js"; //获取token
import { Message } from "element-ui"; //引入element错误提示
// import { config } from "vue/types/umd";
const service = axios.create({
    baseURL: '/api', //baseurl自动添加至请求地址
    timeout: 3000 //请求时长
})

//请求拦截
service.interceptors.request.use((config) => {
    //请求前做什么(token获取设置)
    config.headers['token'] = getToken('token')
    return config
}, (error) => {
    return Promise.reject(error)
})

//添加响应拦截器
service.interceptors.response.use((response) => {
    //对响应数据做些什么
    let { status, message } = response.data
    if (status !== 200) {
        Message({ message: message || 'error', type: 'warning' })
    }
    return response
},
    (error) => {
        return Promise.reject(error)
    })
export default service